package com.machine.action.user;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.machine.bean.User;
import com.machine.service.user.UserServiceDao;
import com.opensymphony.xwork2.ActionSupport;

@Component("userRegisterAction")
@Scope(value="prototype")
public class UserRegisterAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private UserServiceDao userServiceDao;
	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UserServiceDao getUserServiceDao() {
		return userServiceDao;
	}

	@Resource(name = "userService")
	public void setUserServiceDao(UserServiceDao userServiceDao) {
		this.userServiceDao = userServiceDao;
	}
	@Override
	public String execute() throws Exception {
		DateFormat   df   =   new   SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
		String registerTime = df.format(new Date());
		System.out.println("time :" +  registerTime);
		user.setRegisterTime(registerTime);
		user.setSupplierClass("普通");
		if(userServiceDao.save(user) == 1){
			return SUCCESS;
		}else{
			this.addFieldError("user.username", "注册失败");
			return INPUT;
		}
		
	}

}
